import 'reflect-metadata';

export function Get(path?: string): MethodDecorator {
  /*
   * target 类原型 AppController.prototype
   * propertyKey 方法名 getHello
   * descriptor 方法描述符
   * */
  return (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {
    Reflect.defineMetadata('path', path || '', descriptor.value);
    Reflect.defineMetadata('method', 'GET', descriptor.value);
  };
}
export function Post(path?: string): MethodDecorator {
  /*
   * target 类原型 AppController.prototype
   * propertyKey 方法名 getHello
   * descriptor 方法描述符
   * */
  return (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {
    Reflect.defineMetadata('path', path || '', descriptor.value);
    Reflect.defineMetadata('method', 'POST', descriptor.value);
  };
}

export function Redirect(path?: string, statusCode?: number): MethodDecorator {
  return (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {
    Reflect.defineMetadata('redirectUrl', path || '', descriptor.value);
    Reflect.defineMetadata('redirectStatusCode', statusCode, descriptor.value);
  };
}
export function HttpCode(statusCode: number): MethodDecorator {
  return (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {
    Reflect.defineMetadata('httpCode', statusCode, descriptor.value);
  };
}
export function Header(key: string, value: string): MethodDecorator {
  return (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {
    const existingHeaders = Reflect.getMetadata('header', descriptor.value) || [];
    existingHeaders.push({ key, value });
    Reflect.defineMetadata('header', existingHeaders, descriptor.value);
  };
}
